package chapter07

/**
 *
 * @author cdhuangchao3
 * @date 2023/6/11 10:27 AM
 */
object Test13_SimpleFunction {
  def main(args: Array[String]): Unit = {
    val list = List(1, 4, 5, 6, 7, 3)
    val list2 = List(("a", 1), ("b", 3), ("d", 4), ("e", 2))

    // 1.求和
    var sum = 0
    for (elem <- list) sum += elem
    println(sum)

    println(list.sum)

    // 2.求乘积
    println(list.product)
    println("=" * 20)
    // 3.最大值
    println(list.max)
    println(list2.max)
    println(list2.maxBy(tuple => tuple._2))
    println(list2.maxBy(_._2))

    println("=" * 20)
    // 4.最小值
    println(list.min)
    // 5.排序
    println(list.sorted)
    println(list.sorted.reverse)
    println("=" * 20)
    // 传入隐式参数
    println(list.sorted(Ordering[Int].reverse))

    println(list2.sortBy(_._2))
    println(list2.sortBy(_._2)(Ordering[Int].reverse))

    println("=" * 20)
    // sortWith
    println(list.sortWith((a, b) => a > b))
    println(list.sortWith(_ > _))
  }
}
